;(function (window, undefined) {
  var calendar = document.querySelector('#calendar')
  var fullMonth_area = calendar.querySelector('#renderFullYear')
  var fullMonth_title = fullMonth_area.querySelector('h2')
  var detailMonth = calendar.querySelector('#renderMonth')
  var detailMonth_title = detailMonth.querySelector('.title')
  var detailMonth_day = detailMonth.querySelector('.day')

  var tab_num = 0 // tab切换记录值
  var today = new Date()
  var year = today.getFullYear()
  var month = today.getMonth()

  initalToday()

  // 初始化渲染日期
  function initalToday() {
    fullMonth_title.innerHTML = year + '年'
    detailMonth_title.innerHTML = year + '年' + (month + 1) + '月'
    
    tools.renderDetailMonth(detailMonth_day, year, month)
    dateEvent()
  }

  function dateEvent() {
    var control = calendar.querySelector('#control')
    var control_btnPrev = control.querySelector('.btn-prev')
    var control_btnNext = control.querySelector('.btn-next')
		
		//上一个月
    control_btnPrev.onclick = function () {
      if (tab_num == 0) {
        if (month == 0) {
          year --
          month = 11
        } else {
          month --
        }

        tools.renderDetailMonth(detailMonth_day, year, month)
      } else {
        year --
      }

      initalToday()
    }
		
		//下一个月
    control_btnNext.onclick = function () {
      if (tab_num == 0) {
        if (month == 11) {
          year ++
          month = 0
        } else {
          month ++
        }
      } else {
        year ++
      }

      initalToday()
    }

    //点击每一天显示对应的样式
		$("#renderMonth .day li").click(function(){
			var _this = $(this);
			$(".rkNum").html(_this.find($(".showAllList section")).length);
			_this.addClass("selected").siblings().removeClass("selected");
			$(".showAllList").removeClass("show");
			_this.find(".showAllList").addClass("show");
		})
		
    // 初始化事件备注
    function initRemarks(){
      $(".rkNum").html($("#renderMonth .day li.cur-day").find($(".showAllList section")).length);
      $("#renderMonth .day li.cur-day").find($(".showAllList")).addClass("show");
    }

    initRemarks(); 
  }
})(window)